package com.zjw.algorithm.ready1;

public class _最大子数组乘积 {


    public int maxProduct(int[] nums) {

        int[] dp = new int[nums.length];
        int[] dp2 = new int[nums.length];
        //init
        dp[0] = nums[0];
        dp2[0] = nums[0];

        int maxValue = dp[0];

        for (int i = 1; i < dp.length; i++) {
            dp[i] = Math.max(dp[i - 1] * nums[i], Math.max(dp2[i - 1] * nums[i], nums[i]));
            dp2[i] = Math.min(dp2[i - 1] * nums[i], Math.min(dp[i - 1] * nums[i], nums[i]));

            maxValue = Math.max(maxValue, dp[i]);
        }

        return maxValue;
    }
}
